home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / jade / src / amiga_client.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  3KB  |  117 lines

  1. /* amiga_client.c -- client program to communicate with amiga_server.c
  2.    Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
  3.  
  4.    This file is part of Jade.
  5.  
  6.    Jade is free software; you can redistribute it and/or modify it
  7.    under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    Jade is distributed in the hope that it will be useful, but
  12.    WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with Jade; see the file COPYING.    If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <sys/types.h>
  24.  
  25. #include <clib/exec_protos.h>
  26. #include <exec/ports.h>
  27. #include <clib/dos_protos.h>
  28.  
  29. #include "amiga_server.h"
  30.  
  31. int
  32. main(int argc, char *argv[])
  33. {
  34.     u_long linenum;
  35.     u_long result = 0;
  36.     argc--; argv++;
  37.     if(argc == 0)
  38.     {
  39.     fprintf(stderr, "usage: jadeclient { [+LINE-NUMBER] FILE-NAME }...\n");
  40.     return(0);
  41.     }
  42.     while(result == 0 && argc > 0)
  43.     {
  44.     result = 5;
  45.     if(argc >= 1 && **argv == '+')
  46.     {
  47.         linenum = strtol(argv[0], NULL, 0);
  48.         if(linenum <= 0)
  49.         linenum = 1;
  50.         argc--; argv++;
  51.     }
  52.     else
  53.         linenum = 1;
  54.     if(argc > 0)
  55.     {
  56.         /* this should be in public mem really */
  57.         char buf[512];
  58.         if(getcwd(buf, 511))
  59.         {
  60.         if(AddPart(buf, *argv, 511))
  61.         {
  62.             struct MsgPort *mp;
  63.             mp = CreateMsgPort();
  64.             if(mp)
  65.             {
  66.             char domsg = 0;
  67.             /* this should be in public mem really */
  68.             struct clientmsg cm;
  69.             struct MsgPort *servport;
  70.             cm.cm_msg.mn_Length = sizeof(cm);
  71.             cm.cm_msg.mn_ReplyPort = mp;
  72.             cm.cm_file = buf;
  73.             cm.cm_num = linenum;
  74.             Forbid();
  75.             servport = FindPort(JADE_PORT_NAME);
  76.             if(!servport)
  77.             {
  78.                 /* Have to be careful with the forbid/permit, must
  79.                    ensure that no other tasks are running when we
  80.                    locate the port.  */
  81.                 Permit();
  82.                 fprintf(stderr, "Jade not running, waiting...");
  83.                 fflush(stderr);
  84.                 Forbid();
  85.                 do {
  86.                 Permit();
  87.                 sleep(1);
  88.                 Forbid();
  89.                 } while(!(servport = FindPort(JADE_PORT_NAME)));
  90.                 domsg = 1;
  91.             }
  92.             PutMsg(servport, &cm.cm_msg);
  93.             Permit();
  94.             if(domsg)
  95.                 fprintf(stderr, "okay\n");
  96.             WaitPort(mp);
  97.             GetMsg(mp);        /* is this needed? */
  98.             result = cm.cm_num;
  99.             DeleteMsgPort(mp);
  100.             }
  101.             else
  102.             fprintf(stderr, "jadeclient: can't CreateMsgPort()\n");
  103.         }
  104.         else
  105.             fprintf(stderr, "jadeclient: internal buffer overflow\n");
  106.         }
  107.         else
  108.         fprintf(stderr, "jadeclient: internal buffer overflow\n");
  109.     }
  110.     argc--; argv++;
  111.     /* a short pause is nice. */
  112.     if(argc > 0)
  113.         sleep(1);
  114.     }
  115.     return(result);
  116. }
  117.